import libjiamake
from libjiamake import DepIf


def build_cfg():
    cfg = libjiamake.Config()

    feature_asan = cfg.add_feature("asan")
    feature_debug = cfg.add_feature("debug", deps=[feature_asan])

    cflags_asan = cfg.add_cflags("cflags_asan", ["-fsanitize=address"])
    cflags_debug = cfg.add_cflags("cflags_debug", ["-g"])
    cflags = cfg.add_cflags(
        "cflags",
        [
            "-Wall",
            "-Wextra",
            "-Wpedantic",
            "-O2",
            "-I.",
        ],
        deps=[
            DepIf(feature_asan, cflags_asan),
            DepIf(feature_debug, cflags_debug),
        ],
    )

    liblt = cfg.add_library(
        "lt",
        [
            "src/lta.c",
            "src/ltarena.c",
            "src/lterr.c",
            "src/ltini.c",
            "src/ltio.c",
            "src/ltlexer.c",
            "src/ltlog.c",
            "src/ltopt.c",
            "src/ltpanic.c",
            "src/ltprint.c",
            "src/ltt.c",
            "src/ltt_testcase.c",
        ],
        deps=cflags,
    )

    cfg.add_executable(
        "ltt",
        ["src/ltt_main.c"],
        secret_deps=[
            cflags,
            liblt,
        ],
    )

    cfg.add_executable(
        "ltgen",
        [
            "src/ltgen.c",
            "src/ltgen_gens.c",
        ],
        secret_deps=[
            cflags,
            liblt,
        ],
    )

    cfg.add_executable(
        "ltlexer_show",
        [
            "src/ltlexer_show.c",
        ],
        secret_deps=[
            cflags,
            liblt,
        ],
    )

    return cfg


if __name__ == "__main__":
    build_cfg().build()
